home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / xvi.lha / Xvi_V1.0_Src / events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-04  |  3.7 KB  |  205 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)events.c    1.1 (Chris & John Downey) 7/31/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     events.c
  14. * module function:
  15.     Deals with incoming events.
  16.     The main entry point for input to the editor.
  17. * history:
  18.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  19.     Originally by Tim Thompson (twitch!tjt)
  20.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  21.     Heavily modified by Chris & John Downey
  22.     Fixed cursor bug with cancelling command line input.  Dan Schmelzer.
  23.  
  24. ***/
  25.  
  26. #include "xvi.h"
  27.  
  28. static    bool_t    n_proc P((int));
  29. static    bool_t    c_proc P((int));
  30. static    bool_t    d_proc P((int));
  31.  
  32. volatile int    keystrokes;
  33.  
  34. long
  35. xvi_handle_event(ev)
  36. xvEvent    *ev;
  37. {
  38.     bool_t        do_update;
  39.     int        c;
  40.  
  41.     switch (ev->ev_type) {
  42.     case Ev_char:
  43.     keystrokes++;
  44.     map_char(ev->ev_inchar);
  45.     break;
  46.  
  47.     case Ev_timeout:
  48.     if (map_waiting()) {
  49.         map_timeout();
  50.     } else if (keystrokes >= PSVKEYS) {
  51.         do_preserve();
  52.         keystrokes = 0;
  53.     }
  54.     break;
  55.     }
  56.  
  57.     /*
  58.      * Look to see if the event produced any input characters
  59.      * which we can feed into the editor. Call the appropriate
  60.      * function for each one, according to the current State.
  61.      */
  62.     do_update = FALSE;
  63.     while ((c = map_getc()) != EOF) {
  64.     bool_t    (*func)P((int));
  65.  
  66.     switch (State) {
  67.     case NORMAL:
  68.         func = n_proc;
  69.         break;
  70.  
  71.     case CMDLINE:
  72.         func = c_proc;
  73.         break;
  74.  
  75.     case DISPLAY:
  76.         func = d_proc;
  77.         break;
  78.  
  79.     case INSERT:
  80.         func = i_proc;
  81.         break;
  82.  
  83.     case REPLACE:
  84.         func = r_proc;
  85.         break;
  86.     }
  87.     if ((*func)(c)) {
  88.         do_update = TRUE;
  89.     }
  90.  
  91.     /*
  92.      * Look at the resultant state, and the
  93.      * result of the proc() routine, to see
  94.      * whether to update the display.
  95.      */
  96.     switch (State) {
  97.     case CMDLINE:
  98.     case DISPLAY:
  99.         break;
  100.  
  101.     case NORMAL:
  102.     case INSERT:
  103.     case REPLACE:
  104.         if (do_update) {
  105.         move_window_to_cursor(curwin);
  106.         cursupdate(curwin);
  107.         wind_goto(curwin);
  108.         }
  109.     }
  110.     }
  111.  
  112.     if (kbdintr) {
  113.     if (imessage) {
  114.         show_message(curwin, "Interrupted");
  115.         wind_goto(curwin);    /* put cursor back */
  116.     }
  117.     imessage = (kbdintr = 0);
  118.     }
  119.  
  120.     if (map_waiting()) {
  121.     return((long) Pn(P_timeout));
  122.     } else if (keystrokes >= PSVKEYS) {
  123.     return((long) Pn(P_preservetime) * 1000);
  124.     } else {
  125.     return(0);
  126.     }
  127. }
  128.  
  129. /*
  130.  * Process the given character in command mode.
  131.  */
  132. static bool_t
  133. n_proc(c)
  134. int    c;
  135. {
  136.     unsigned    savecho;
  137.     bool_t    result;
  138.  
  139.     savecho = echo;
  140.     result = normal(c);
  141.     echo = savecho;
  142.     return(result);
  143. }
  144.  
  145. /*
  146.  * Returns TRUE if screen wants updating, FALSE otherwise.
  147.  */
  148. static bool_t
  149. c_proc(c)
  150. int    c;
  151. {
  152.     char    *cmdline;
  153.  
  154.     switch (cmd_input(curwin, c)) {
  155.     case cmd_CANCEL:
  156.     /*
  157.      * Put the status line back as it should be.
  158.      */
  159.     show_file_info(curwin);
  160.     wind_goto(curwin);    /* Added to fix cursor bug. DAS. */
  161.     update_window(curwin);
  162.     return(FALSE);
  163.  
  164.     case cmd_INCOMPLETE:
  165.     return(FALSE);
  166.  
  167.     case cmd_COMPLETE:
  168.     cmdline = get_cmd(curwin);
  169.     (void) yank_str(cmdline[0], cmdline, TRUE);
  170.     switch (cmdline[0]) {
  171.     case '/':
  172.     case '?':
  173.         (void) dosearch(curwin, cmdline + 1, cmdline[0]);
  174.         move_window_to_cursor(curwin);
  175.         break;
  176.  
  177.     case '!':
  178.         do_pipe(curwin, cmdline + 1);
  179.         break;
  180.  
  181.     case ':':
  182.         do_colon(cmdline + 1, TRUE);
  183.     }
  184.     return(TRUE);
  185.     }
  186.     /*NOTREACHED*/
  187. }
  188.  
  189. /*ARGSUSED*/
  190. static bool_t
  191. d_proc(c)
  192. int    c;
  193. {
  194.     if (c == CTRL('C')) {
  195.     /*
  196.      * In some environments it's possible to type
  197.      * control-C without actually generating an interrupt,
  198.      * but if they do, in this context, they probably want
  199.      * the semantics of an interrupt anyway.
  200.      */
  201.     imessage = (kbdintr = 1);
  202.     }
  203.     return(disp_screen(curwin));
  204. }
  205.